package one.two.nine;

import edu.princeton.cs.algs4.Counter;

public class RankCounter {

	private static int rank(int k, int[] a, Counter c) {
		// Counter c = new Counter("counter");
		int l = 0;
		int h = a.length - 1;
		while (l <= h) {
			int mid = l + (h - l) / 2;
			if (k < a[mid]) {
				System.out.println("<");
				c.increment();
				h = mid - 1;
			} else if (k > a[mid]) {
				System.out.println(">");
				c.increment();
				l = mid + 1;
			} else {
				return mid;
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
		Counter c = new Counter("coutner");

		int r = rank(1, a, c);
		System.out.println(r);
		System.out.println(c.tally());
	}

}
